
#define key 5
#define keystate (digitalRead(key))
#define light LOW
long timer=0;

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);
  pinMode(key,INPUT);
  digitalWrite(LED_BUILTIN,HIGH);
  Serial.begin(9600);
  timer=millis();
}

void loop() {

  int doOnce=1;
  if(keystate==0)
  {
    timer=millis();
    digitalWrite(LED_BUILTIN,~light);
    pinMode(key,OUTPUT);
    digitalWrite(key,HIGH);
    pinMode(key,INPUT);
    Serial.println("带了带了");
  }
  else
  {
    while(millis()-timer>=5000 && keystate==1)
    {
      if(doOnce)
      {
        Serial.println("5秒已到，未戴头盔");
        digitalWrite(LED_BUILTIN,light);
      }
    }
  }
  
  

}
